<template>
    <div>
        <v-touch v-on:swiperight="onSwipeRight" :swipe-options="{direction: 'horizontal'}">
        <x-header title="值班打卡" :left-options="{backText:''}"
                    @on-click-back="$router.go(-1)" >     
        </x-header>
        <div class="info">
            <div v-if="imgUrl == ''">
                <div v-if="user.ADUSER_NAME.length < 3" class="no_photo">
                    {{user.ADUSER_NAME}}
                </div>
                <div v-else class="no_photo">
                    {{user.ADUSER_NAME.substring(0,1)}}
                </div>
            </div>
            <div v-else>
                 <img :src="imgUrl" class="photo"/>
            </div>
            <div class="text_info">
                <div class="text_name">{{user.ADUSER_NAME}}</div>
                <div class="text_dept">{{user.Third_DeptName}}</div>
            </div>
        </div>

        <flow orientation="vertical" style="height:200px;padding:15px" v-show="shangxiaban">
            <flow-state>
                <div slot="title">值班开始时间  {{planStartTime.substring(0,5)}}</div>
            </flow-state>
            <flow-line></flow-line>

            <flow-state>
                <div slot="title">值班结束时间  {{planEndTime.substring(0,5)}}</div>
            </flow-state>
        </flow>
        <div class="cardTime" v-show="startTimeFlag">打卡时间 {{actualStartTime.substring(0,5)}}</div>
        <div class="cardTime1" v-show="endTimeFlag">打卡时间 {{actualEndTime.substring(0,5)}}</div>
        <div class="late" v-show="lateFlag">迟到</div>
        <div class="location" v-show="startTimeFlag">
            <img src="../../assets/img/location.png" style="width:20px;height:20px"/>
            <div class="location_text">{{address}}</div>
        </div>
         <div class="location1" v-show="endTimeFlag">
            <img src="../../assets/img/location.png" style="width:20px;height:20px"/>
            <div class="location_text">{{address}}</div>
        </div>
        <div class="updateCard" v-show="updateStartTimeFlag" @click="updateStartTime">
            更新打卡 >
        </div>
         <div class="updateCard1" v-show="updateEndTimeFlag" @click="updateEndTime">
            更新打卡 >
        </div>
        <div class="circular" @click="dutyCard" v-show="circularFlag">
            <div class="circular_text">打卡</div>
            <div class="circular_time">{{time}}</div>
        </div>
        <div class="circularQD" @click="dutyQDCard" v-show="circularQDFlag">
            <div class="circular_text_QD">签到</div>
            <div class="circular_time_QD">{{time}}</div>
        </div>
        <div class="judgeAndReLoc" v-show="judgeAndReLocFlag">
            <img src="../../assets/img/inScope.png" style="width:20px;height:20px" v-show="inScope"/>
            <div class="isInScope" v-show="inScope">已进入考勤范围</div>
            <img src="../../assets/img/outScope.png" style="width:20px;height:20px" v-show="outScope"/>
            <div class="isInScope" v-show="outScope">未进入考勤范围</div>
            <div class="reLocation" @click="reLocation">重新定位</div>
        </div>
        <!-- <div class="sup" v-show="takePhoto"></div>  v-show="takePhoto"-->
        <div class="takePhoto" v-show="takePhoto">
            <picture-upload :pageToken="pageToken" v-model="fieldToken" title="上传现场照片" :width="width" :height="heigth" :readonly='!circularQDFlag'></picture-upload>
        </div>
        <div class="cardQDTime" v-show="startTimeFlag">打卡时间 {{actualStartTime.substring(0,5)}}</div>
        <Toast :value="toastValue" :is-show-mask="true" text="暂无打卡计划"></Toast>
        <Toast :value="toastValueNoIn" :is-show-mask="true" text="不在打卡范围，请重新定位"></Toast>
        <Toast :value="toastValueNotOnDuty" :is-show-mask="true" text="当前无需考勤"></Toast>
        <Toast :value="toastValueTakePhoto" :is-show-mask="true" text="请先进行拍照"></Toast>
        </v-touch>
    </div>
</template>

<script>
import { Flow, FlowState, FlowLine ,Toast} from 'vux'
import {location} from '../../assets/js/locatemyself'
import { setTimeout } from 'timers';
import $ from 'jquery'
//全局使用$vue代替this
var $vue = {}
var PI = 3.14159265358979324;
export default {
    name : "dutyCard",
    components: {
        Flow,
        FlowState,
        FlowLine,
        Toast
    },
    beforeCreate(){
        //全局使用$vue代替this
        $vue = this
    },
    data(){
        return {
            width:'100px',
            heigth:'100px',
            user : this.$store.state.user,
            imgUrl : "",
            time : "",
            pageToken : "",
            fieldToken : "",
            planList : [],
            infoList:[],
            cardTime : "",
            flag : 0,
            today : "",
            workMode : "",
            planStartTime : "",
            planEndTime : "",
            SYSPRJID : "",
            PRJNAME : "",
            workPosition : "",
            planMinDate : "",
            planMaxDate : "",
            GUID : "",
            actualStartTime : "",
            actualEndTime : "",
            startLocation : "",
            endLocation : "",   
            buttonId : "",     
            startTimeFlag : false,
            endTimeFlag : false,
            circularFlag : true,
            circularQDFlag : false,
            judgeAndReLocFlag : true,
            updateStartTimeFlag : false,
            updateEndTimeFlag : false,
            currentLat : "",
            currentLng : "",
            address:"",
            path : [],
            lateFlag : false,
            point : [],
            inScope : false,
            outScope : false,
            toastValue : false,
            toastValueNoIn : false,
            takePhoto : false,
            shangxiaban : false,
            toastValueNotOnDuty : false,
            toastValueTakePhoto : false,
        }
    },
    mounted(){
        this.timer = setInterval(() => {
            this.time = this.getTime(new Date()); // 修改数据date
        }, 1000)
        this.getUser();
        this.getUserImg();
        this.getToday();//获取当天日期
        this.pageToken = this.guid();
        // this.fieldToken = this.guid();
        this.buttonId = this.guid();
        this.getCheckPlan();//获取打卡计划
        setTimeout(()=>{
            this.getCheckOn();//获取当天打卡信息
        },500)
        
    },
    
    destroyed () {
    if (this.timer) { 
        clearInterval(this.timer)
    }
    },
    methods:{
        judgeIsInscope(){
            console.log("wwqeqweqeqweqweqw",this.point)
            // var isPointlnRing = AMap.GeometryUtil.isPointInRing(this.point,this.path)
            // //console.log("isisisis",isPointlnRing);
            // if(isPointlnRing){
            //     this.inScope =  true;
            // }else{
            //     this.outScope = true;
            // }
           
            var counter = 0;
            var i;
            var xinters;
            var p1, p2;
            var pointCount = this.path.length;
            console.log("length",pointCount);
            p1 = this.path[0];
            console.log("p1",p1);
            for (i = 0; i < pointCount; i++) {
                p2 = this.path[i % pointCount];
                console.log("p2",p2);
                if (
                    this.point[0] > Math.min(p1[0], p2[0]) &&
                    this.point[0] <= Math.max(p1[0], p2[0])
                ) {
                    if (this.point[1] <= Math.max(p1[1], p2[1])) {
                        if (p1[0] != p2[0]) {
                            xinters =
                                (this.point[0] - p1[0]) *
                                    (p2[1] - p1[1]) /
                                    (p2[0] - p1[0]) +
                                p1[1];
                            if (p1[1] == p2[1] || this.point[1] <= xinters) {
                                counter++;
                            }
                        }
                    }
                }
                p1 = p2;
                console.log(counter);
            }
            if (counter % 2 == 0) {
                return false;
            } else {
                return true;
            }
        },
         //右滑返回上一层
      onSwipeRight () {
        this.$router.go(-1)
      },
        updateStartTime(){
            this.getCurrentPosition();
            //var point = [this.currentLng,this.currentLat];
            // console.log("point",point);
            // console.log("point",this.path);
            //var isPointlnRing = AMap.GeometryUtil.isPointInRing(point,this.path)
            if(this.judgeIsInscope()){
                 var params = {
                        "_method": "formService.saveFormData",
                        "requestEventData": {
                        "eventType": "formSubmitEvent",
                        "formType": 1,
                        "bizObjId": "PMCOMPRE_CHECKON",
                        "formId": "PMCOMPRE_CHECKON_add",
                        "buttonId": this.buttonid
                        },
                        "_OBJ_NAME_": "PMCOMPRE_CHECKON",
                        "_FORM_ID_": "PMCOMPRE_CHECKON_add",
                        "useType": "modify",
                        "pageToken": this.pageToken,
                        "formData": {
                        "objName": "PMCOMPRE_CHECKON",
                        "pks": ["GUID"],
                        "data": [{
                            "rowData": [
                            { "DataTarget": "GUID", "Value": this.GUID, "OriginalValue": this.GUID, "PK": true, "DataType": "String" },
                            { "DataTarget": "SYSPRJID", "Value": this.SYSPRJID, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "PRJNAME", "Value": this.PRJNAME, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "PLANSTARTDATE", "Value": this.planMinDate, "OriginalValue": null, "PK": false, "DataType": "TimeStamp" },
                            { "DataTarget": "PLANENDDATE", "Value": this.planMaxDate, "OriginalValue": null, "PK": false, "DataType": "TimeStamp" },
                            { "DataTarget": "PLANSTARTTIME", "Value": this.planStartTime, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "PLANENDTIME", "Value": this.planEndTime, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "PLANLOCATION", "Value": this.workPosition, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "CHECKONDATE", "Value": this.today + " 00:00:00.000", "OriginalValue": null, "PK": false, "DataType": "TimeStamp" },
                            { "DataTarget": "CHECKONSTARTTIME", "Value": this.time, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "CHECKONENDTIME", "Value": this.actualEndTime, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "STARTLOCATION", "Value": this.startLocation, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "ENDLOCATION", "Value": this.endLocation, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "ATTACHMENTS", "Value": this.fieldToken, "OriginalValue": null, "PK": false, "DataType": "Store.ecidiDoc" },
                            { "DataTarget": "USERNAME", "Value": this.user.loginId, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "USERFULLNAME", "Value": this.user.userName, "OriginalValue": null, "PK": false, "DataType": "String" },
                            ],
                            "children": []
                        }]
                        },
                        "_ATTACHMENT_DELETE_IDS_": "",
                        "formInfo": {
                        "GUID": this.GUID,
                        "SYSPRJID": this.SYSPRJID,
                        "PRJNAME": this.PRJNAME,
                        "PLANSTARTDATE": this.planMinDate,
                        "PLANENDDATE": this.planMaxDate,
                        "PLANSTARTTIME": this.planStartTime,
                        "PLANENDTIME": this.planEndTime,
                        "PLANLOCATION": this.workPosition,
                        "CHECKONDATE": this.today,
                        "CHECKONSTARTTIME": this.time,
                        "CHECKONENDTIME": this.actualEndTime,
                        "STARTLOCATION": this.startLocation,
                        "ENDLOCATION": this.endLocation,
                        "ATTACHMENTS": this.fieldToken,
                        "USERNAME": this.user.loginId,
                        "USERFULLNAME": this.user.userName,
                        }

                    }
                    let json = {
                        FixJSON: JSON.stringify(params),
                    }

                    this.$ajax({
                        url : this.COMMON_URL,
                        method : 'post',
                        data : json
                    }).then(res=>{
                        this.actualStartTime = this.time;
                    })
                }else{
                    // alert("不在打卡范围");
                    this.toastValueNoIn = true
                }
        },
       updateEndTime(){
           this.getCurrentPosition();
            // var point = [this.currentLng,this.currentLat];
            // console.log("point",point);
            // console.log("point",this.path);
            // var isPointlnRing = AMap.GeometryUtil.isPointInRing(point,this.path)
            if(this.judgeIsInscope()){
                 var params = {
                        "_method": "formService.saveFormData",
                        "requestEventData": {
                        "eventType": "formSubmitEvent",
                        "formType": 1,
                        "bizObjId": "PMCOMPRE_CHECKON",
                        "formId": "PMCOMPRE_CHECKON_add",
                        "buttonId": this.buttonid
                        },
                        "_OBJ_NAME_": "PMCOMPRE_CHECKON",
                        "_FORM_ID_": "PMCOMPRE_CHECKON_add",
                        "useType": "modify",
                        "pageToken": this.pageToken,
                        "formData": {
                        "objName": "PMCOMPRE_CHECKON",
                        "pks": ["GUID"],
                        "data": [{
                            "rowData": [
                            { "DataTarget": "GUID", "Value": this.GUID, "OriginalValue": this.GUID, "PK": true, "DataType": "String" },
                            { "DataTarget": "SYSPRJID", "Value": this.SYSPRJID, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "PRJNAME", "Value": this.PRJNAME, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "PLANSTARTDATE", "Value": this.planMinDate, "OriginalValue": null, "PK": false, "DataType": "TimeStamp" },
                            { "DataTarget": "PLANENDDATE", "Value": this.planMaxDate, "OriginalValue": null, "PK": false, "DataType": "TimeStamp" },
                            { "DataTarget": "PLANSTARTTIME", "Value": this.planStartTime, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "PLANENDTIME", "Value": this.planEndTime, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "PLANLOCATION", "Value": this.workPosition, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "CHECKONDATE", "Value": this.today + " 00:00:00.000", "OriginalValue": null, "PK": false, "DataType": "TimeStamp" },
                            { "DataTarget": "CHECKONSTARTTIME", "Value": this.actualStartTime, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "CHECKONENDTIME", "Value": this.time, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "STARTLOCATION", "Value": this.startLocation, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "ENDLOCATION", "Value": this.endLocation, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "ATTACHMENTS", "Value": this.fieldToken, "OriginalValue": null, "PK": false, "DataType": "Store.ecidiDoc" },
                            { "DataTarget": "USERNAME", "Value": this.user.loginId, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "USERFULLNAME", "Value": this.user.userName, "OriginalValue": null, "PK": false, "DataType": "String" },
                            ],
                            "children": []
                        }]
                        },
                        "_ATTACHMENT_DELETE_IDS_": "",
                        "formInfo": {
                        "GUID": this.GUID,
                        "SYSPRJID": this.SYSPRJID,
                        "PRJNAME": this.PRJNAME,
                        "PLANSTARTDATE": this.planMinDate,
                        "PLANENDDATE": this.planMaxDate,
                        "PLANSTARTTIME": this.planStartTime,
                        "PLANENDTIME": this.planEndTime,
                        "PLANLOCATION": this.workPosition,
                        "CHECKONDATE": this.today,
                        "CHECKONSTARTTIME": this.actualStartTime,
                        "CHECKONENDTIME": this.time,
                        "STARTLOCATION": this.startLocation,
                        "ENDLOCATION": this.endLocation,
                        "ATTACHMENTS": this.fieldToken,
                        "USERNAME": this.user.loginId,
                        "USERFULLNAME": this.user.userName,
                        }

                    }
                    let json = {
                        FixJSON: JSON.stringify(params),
                    }

                    this.$ajax({
                        url : this.COMMON_URL,
                        method : 'post',
                        data : json
                    }).then(res=>{
                        this.actualEndTime = this.time;
                    })
                }else{
                    // alert("不在打卡范围");
                    this.toastValueNoIn = true
                }
       
       },
        reLocation(){
            this.getCurrentPosition();
        },
         /**获取GPS定位*/
        getCurrentPosition() {
            navigator.geolocation.getCurrentPosition(onSuccess, onError);
            // let _that = this;
            // let geolocation = location.initMap(""); //定位
            // AMap.event.addListener(geolocation, "complete", result => {
            //     var lat = result.position.lat;
            //     var lng = result.position.lng
            //     console.log("location",result);
            //     $vue.address = result.formattedAddress;
            //     $vue.transformGCJ2WGS(lat,lng)//坐标转换（高德转天地图）
            // });
             function onSuccess(position) {
                 $vue.currentLat = position.coords.latitude;
                 $vue.currentLng = position.coords.longitude;
                $vue.point = [$vue.currentLng,$vue.currentLat];
                 //$vue.point = [119.961138,30.272817]
                 console.log("纬度：",$vue.currentLat);
                 console.log("经度：",$vue.currentLng);
                 console.log("点：",$vue.point);
                 //console.log("是否在范围内：",$vue.judgeIsInscope());
                 if($vue.judgeIsInscope()){
                     this.inScope =  true;
                 }else{
                     this.outScope = true;
                 }
             };
                //     alert('纬度: '          + position.coords.latitude          + '\n' +
                //           '经度: '         + position.coords.longitude         + '\n' +
                //           '海拔: '          + position.coords.altitude          + '\n' +
                //           '水平精度: '          + position.coords.accuracy          + '\n' +
                //           '垂直精度: ' + position.coords.altitudeAccuracy  + '\n' +
                //           '方向: '           + position.coords.heading           + '\n' +
                //           '速度: '             + position.coords.speed             + '\n' +
                //           '时间戳: '         + position.timestamp                + '\n');
                // };
 
                //定位数据获取失败响应
                function onError(error) {
                    alert('code: '    + error.code    + '\n' +
                          'message: ' + error.message + '\n');
                }
        },
        getToday(){
            var date = new Date();
            var year = date.getFullYear();
            var month = date.getMonth() + 1;
            if(month < 10){
                month = "0" + month;
            }
            var day = date.getDate();
            this.today = year + "-" + month + "-" + day;
        },
        dutyQDCard(){
            if(this.judgeIsInscope()){
            if(this.workMode == '签到'){
             var params = {},
                    params = {
                        "_method": "formService.saveFormData",
                        "requestEventData": {
                        "eventType": "formSubmitEvent",
                        "formType": 1,
                        "bizObjId": "PMCOMPRE_CHECKON",
                        "formId": "PMCOMPRE_CHECKON_add",
                        "buttonId": this.buttonid
                        },
                        "_OBJ_NAME_": "PMCOMPRE_CHECKON",
                        "_FORM_ID_": "PMCOMPRE_CHECKON_add",
                        "useType": "add",
                        "pageToken": this.pageToken,
                        "formData": {
                        "objName": "PMCOMPRE_CHECKON",
                        "pks": ["GUID"],
                        "data": [{
                            "rowData": [
                            { "DataTarget": "GUID", "Value": this.GUID, "OriginalValue": null, "PK": true, "DataType": "String" },
                            { "DataTarget": "SYSPRJID", "Value": this.SYSPRJID, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "PRJNAME", "Value": this.PRJNAME, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "PLANSTARTDATE", "Value": this.planMinDate, "OriginalValue": null, "PK": false, "DataType": "TimeStamp" },
                            { "DataTarget": "PLANENDDATE", "Value": this.planMaxDate, "OriginalValue": null, "PK": false, "DataType": "TimeStamp" },
                            { "DataTarget": "PLANSTARTTIME", "Value": this.planStartTime, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "PLANENDTIME", "Value": this.planEndTime, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "PLANLOCATION", "Value": this.workPosition, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "CHECKONDATE", "Value": this.today + " 00:00:00.000", "OriginalValue": null, "PK": false, "DataType": "TimeStamp" },
                            { "DataTarget": "CHECKONSTARTTIME", "Value": this.time, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "CHECKONENDTIME", "Value": this.actualEndTime, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "STARTLOCATION", "Value": this.startLocation, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "ENDLOCATION", "Value": this.endLocation, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "ATTACHMENTS", "Value": this.fieldToken, "OriginalValue": null, "PK": false, "DataType": "Store.ecidiDoc" },
                            { "DataTarget": "USERNAME", "Value": this.user.loginId, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "USERFULLNAME", "Value": this.user.userName, "OriginalValue": null, "PK": false, "DataType": "String" },
                            ],
                            "children": []
                        }]
                        },
                        "_ATTACHMENT_DELETE_IDS_": "",
                        "formInfo": {
                        "GUID": this.GUID,
                        "SYSPRJID": this.SYSPRJID,
                        "PRJNAME": this.PRJNAME,
                        "PLANSTARTDATE": this.planMinDate,
                        "PLANENDDATE": this.planMaxDate,
                        "PLANSTARTTIME": this.planStartTime,
                        "PLANENDTIME": this.planEndTime,
                        "PLANLOCATION": this.workPosition,
                        "CHECKONDATE": this.today,
                        "CHECKONSTARTTIME": this.actualStartTime,
                        "CHECKONENDTIME": this.actualEndTime,
                        "STARTLOCATION": this.startLocation,
                        "ENDLOCATION": this.endLocation,
                        "ATTACHMENTS": this.fieldToken,
                        "USERNAME": this.user.loginId,
                        "USERFULLNAME": this.user.userName,
                        }

                    }
                    let json = {
                        FixJSON: JSON.stringify(params),
                    }

                    this.$ajax({
                        url : this.COMMON_URL,
                        method : 'post',
                        data : json
                    }).then(res=>{
                        this.actualStartTime = this.time;
                        this.startTimeFlag = true
                        this.circularFlag = false
                        this.circularQDFlag = false
                        this.judgeAndReLocFlag = false

                    })

                }else if(this.workMode =="签到+拍照"){
                    if(this.fieldToken == ""){
                        this.toastValueTakePhoto = true;
                    }else{
                        var params = {},
                    params = {
                        "_method": "formService.saveFormData",
                        "requestEventData": {
                        "eventType": "formSubmitEvent",
                        "formType": 1,
                        "bizObjId": "PMCOMPRE_CHECKON",
                        "formId": "PMCOMPRE_CHECKON_add",
                        "buttonId": this.buttonid
                        },
                        "_OBJ_NAME_": "PMCOMPRE_CHECKON",
                        "_FORM_ID_": "PMCOMPRE_CHECKON_add",
                        "useType": "add",
                        "pageToken": this.pageToken,
                        "formData": {
                        "objName": "PMCOMPRE_CHECKON",
                        "pks": ["GUID"],
                        "data": [{
                            "rowData": [
                            { "DataTarget": "GUID", "Value": this.GUID, "OriginalValue": null, "PK": true, "DataType": "String" },
                            { "DataTarget": "SYSPRJID", "Value": this.SYSPRJID, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "PRJNAME", "Value": this.PRJNAME, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "PLANSTARTDATE", "Value": this.planMinDate, "OriginalValue": null, "PK": false, "DataType": "TimeStamp" },
                            { "DataTarget": "PLANENDDATE", "Value": this.planMaxDate, "OriginalValue": null, "PK": false, "DataType": "TimeStamp" },
                            { "DataTarget": "PLANSTARTTIME", "Value": this.planStartTime, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "PLANENDTIME", "Value": this.planEndTime, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "PLANLOCATION", "Value": this.workPosition, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "CHECKONDATE", "Value": this.today + " 00:00:00.000", "OriginalValue": null, "PK": false, "DataType": "TimeStamp" },
                            { "DataTarget": "CHECKONSTARTTIME", "Value": this.time, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "CHECKONENDTIME", "Value": this.actualEndTime, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "STARTLOCATION", "Value": this.startLocation, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "ENDLOCATION", "Value": this.endLocation, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "ATTACHMENTS", "Value": this.fieldToken, "OriginalValue": null, "PK": false, "DataType": "Store.ecidiDoc" },
                            { "DataTarget": "USERNAME", "Value": this.user.loginId, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "USERFULLNAME", "Value": this.user.userName, "OriginalValue": null, "PK": false, "DataType": "String" },
                            ],
                            "children": []
                        }]
                        },
                        "_ATTACHMENT_DELETE_IDS_": "",
                        "formInfo": {
                        "GUID": this.GUID,
                        "SYSPRJID": this.SYSPRJID,
                        "PRJNAME": this.PRJNAME,
                        "PLANSTARTDATE": this.planMinDate,
                        "PLANENDDATE": this.planMaxDate,
                        "PLANSTARTTIME": this.planStartTime,
                        "PLANENDTIME": this.planEndTime,
                        "PLANLOCATION": this.workPosition,
                        "CHECKONDATE": this.today,
                        "CHECKONSTARTTIME": this.actualStartTime,
                        "CHECKONENDTIME": this.actualEndTime,
                        "STARTLOCATION": this.startLocation,
                        "ENDLOCATION": this.endLocation,
                        "ATTACHMENTS": this.fieldToken,
                        "USERNAME": this.user.loginId,
                        "USERFULLNAME": this.user.userName,
                        }

                    }
                    let json = {
                        FixJSON: JSON.stringify(params),
                    }

                    this.$ajax({
                        url : this.COMMON_URL,
                        method : 'post',
                        data : json
                    }).then(res=>{
                        this.startTimeFlag = true
                        this.actualStartTime = this.time;
                        this.circularQDFlag = false
                    })
                    }
                }
            }else{
                this.toastValueNoIn = true
            }
            },
        dutyCard(){
            this.getCurrentPosition();
            if(this.judgeIsInscope()){
                var params = {}
                if(this.GUID == ""){
                    params = {
                        "_method": "formService.saveFormData",
                        "requestEventData": {
                        "eventType": "formSubmitEvent",
                        "formType": 1,
                        "bizObjId": "PMCOMPRE_CHECKON",
                        "formId": "PMCOMPRE_CHECKON_add",
                        "buttonId": this.buttonid
                        },
                        "_OBJ_NAME_": "PMCOMPRE_CHECKON",
                        "_FORM_ID_": "PMCOMPRE_CHECKON_add",
                        "useType": "add",
                        "pageToken": this.pageToken,
                        "formData": {
                        "objName": "PMCOMPRE_CHECKON",
                        "pks": ["GUID"],
                        "data": [{
                            "rowData": [
                            { "DataTarget": "GUID", "Value": this.GUID, "OriginalValue": null, "PK": true, "DataType": "String" },
                            { "DataTarget": "SYSPRJID", "Value": this.SYSPRJID, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "PRJNAME", "Value": this.PRJNAME, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "PLANSTARTDATE", "Value": this.planMinDate, "OriginalValue": null, "PK": false, "DataType": "TimeStamp" },
                            { "DataTarget": "PLANENDDATE", "Value": this.planMaxDate, "OriginalValue": null, "PK": false, "DataType": "TimeStamp" },
                            { "DataTarget": "PLANSTARTTIME", "Value": this.planStartTime, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "PLANENDTIME", "Value": this.planEndTime, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "PLANLOCATION", "Value": this.workPosition, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "CHECKONDATE", "Value": this.today + " 00:00:00.000", "OriginalValue": null, "PK": false, "DataType": "TimeStamp" },
                            { "DataTarget": "CHECKONSTARTTIME", "Value": this.time, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "CHECKONENDTIME", "Value": this.actualEndTime, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "STARTLOCATION", "Value": this.startLocation, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "ENDLOCATION", "Value": this.endLocation, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "ATTACHMENTS", "Value": this.fieldToken, "OriginalValue": null, "PK": false, "DataType": "Store.ecidiDoc" },
                            { "DataTarget": "USERNAME", "Value": this.user.loginId, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "USERFULLNAME", "Value": this.user.userName, "OriginalValue": null, "PK": false, "DataType": "String" },
                            ],
                            "children": []
                        }]
                        },
                        "_ATTACHMENT_DELETE_IDS_": "",
                        "formInfo": {
                        "GUID": this.GUID,
                        "SYSPRJID": this.SYSPRJID,
                        "PRJNAME": this.PRJNAME,
                        "PLANSTARTDATE": this.planMinDate,
                        "PLANENDDATE": this.planMaxDate,
                        "PLANSTARTTIME": this.planStartTime,
                        "PLANENDTIME": this.planEndTime,
                        "PLANLOCATION": this.workPosition,
                        "CHECKONDATE": this.today,
                        "CHECKONSTARTTIME": this.actualStartTime,
                        "CHECKONENDTIME": this.actualEndTime,
                        "STARTLOCATION": this.startLocation,
                        "ENDLOCATION": this.endLocation,
                        "ATTACHMENTS": this.fieldToken,
                        "USERNAME": this.user.loginId,
                        "USERFULLNAME": this.user.userName,
                        }

                    }
                }else{
                    params = {
                        "_method": "formService.saveFormData",
                        "requestEventData": {
                        "eventType": "formSubmitEvent",
                        "formType": 1,
                        "bizObjId": "PMCOMPRE_CHECKON",
                        "formId": "PMCOMPRE_CHECKON_add",
                        "buttonId": this.buttonid
                        },
                        "_OBJ_NAME_": "PMCOMPRE_CHECKON",
                        "_FORM_ID_": "PMCOMPRE_CHECKON_add",
                        "useType": "modify",
                        "pageToken": this.pageToken,
                        "formData": {
                        "objName": "PMCOMPRE_CHECKON",
                        "pks": ["GUID"],
                        "data": [{
                            "rowData": [
                            { "DataTarget": "GUID", "Value": this.GUID, "OriginalValue": this.GUID, "PK": true, "DataType": "String" },
                            { "DataTarget": "SYSPRJID", "Value": this.SYSPRJID, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "PRJNAME", "Value": this.PRJNAME, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "PLANSTARTDATE", "Value": this.planMinDate, "OriginalValue": null, "PK": false, "DataType": "TimeStamp" },
                            { "DataTarget": "PLANENDDATE", "Value": this.planMaxDate, "OriginalValue": null, "PK": false, "DataType": "TimeStamp" },
                            { "DataTarget": "PLANSTARTTIME", "Value": this.planStartTime, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "PLANENDTIME", "Value": this.planEndTime, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "PLANLOCATION", "Value": this.workPosition, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "CHECKONDATE", "Value": this.today + " 00:00:00.000", "OriginalValue": null, "PK": false, "DataType": "TimeStamp" },
                            { "DataTarget": "CHECKONSTARTTIME", "Value": this.actualStartTime, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "CHECKONENDTIME", "Value": this.time, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "STARTLOCATION", "Value": this.startLocation, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "ENDLOCATION", "Value": this.endLocation, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "ATTACHMENTS", "Value": this.fieldToken, "OriginalValue": null, "PK": false, "DataType": "Store.ecidiDoc" },
                            { "DataTarget": "USERNAME", "Value": this.user.loginId, "OriginalValue": null, "PK": false, "DataType": "String" },
                            { "DataTarget": "USERFULLNAME", "Value": this.user.userName, "OriginalValue": null, "PK": false, "DataType": "String" },
                            ],
                            "children": []
                        }]
                        },
                        "_ATTACHMENT_DELETE_IDS_": "",
                        "formInfo": {
                        "GUID": this.GUID,
                        "SYSPRJID": this.SYSPRJID,
                        "PRJNAME": this.PRJNAME,
                        "PLANSTARTDATE": this.planMinDate,
                        "PLANENDDATE": this.planMaxDate,
                        "PLANSTARTTIME": this.planStartTime,
                        "PLANENDTIME": this.planEndTime,
                        "PLANLOCATION": this.workPosition,
                        "CHECKONDATE": this.today,
                        "CHECKONSTARTTIME": this.actualStartTime,
                        "CHECKONENDTIME": this.actualEndTime,
                        "STARTLOCATION": this.startLocation,
                        "ENDLOCATION": this.endLocation,
                        "ATTACHMENTS": this.fieldToken,
                        "USERNAME": this.user.loginId,
                        "USERFULLNAME": this.user.userName,
                        }

                    }
                }

                let json = {
                    FixJSON: JSON.stringify(params),
                }

                this.$ajax({
                    url : this.COMMON_URL,
                    method : 'post',
                    data : json
                }).then(res=>{
                    console.log("daka",res);
                    if(!this.startTimeFlag && !this.endTimeFlag){
                        this.actualStartTime = this.time;
                        if(this.time > this.planList.STARTTIME){
                            this.lateFlag = true;
                        }
                        this.startTimeFlag = true;
                        this.updateStartTimeFlag = true;
                    }else if(this.startTimeFlag && !this.endTimeFlag){
                        this.actualEndTime = this.time;
                        this.circularFlag = false;
                        this.judgeAndReLocFlag = false;
                        this.endTimeFlag = true;
                        this.updateEndTimeFlag = true;
                        this.updateStartTimeFlag = false;
                    }
                })
            }else{
                this.toastValueNoIn = true;
            }
        },  
        getCheckOn(){
            this.$ajax({
                url : this.COMMON_URL,
                method : 'post',
                data : {
                    _method : "PMCOMPRE_CHECKON.getCheckInfo",
                    filter : "userName='" + this.user.loginId + "' and CHECKONDATE = '" + this.today + "'"
                },
                async : false
            }).then(res =>{
                console.log("checkon",res);
                if(res.data.returnValue.length > 0){
                    this.startTimeFlag = true;
                    this.updateStartTimeFlag = true;
                    this.infoList = res.data.returnValue[0];
                    this.actualStartTime = this.infoList.CHECKONSTARTTIME;
                    this.actualEndTime = this.infoList.CHECKONENDTIME;
                    this.startLocation = this.infoList.STARTLOCATION;
                    this.endLocation = this.infoList.ENDLOCATION;
                    this.GUID = this.infoList.GUID;
                    if(this.workMode == '上下班'){
                        if(this.actualStartTime > this.planList.STARTTIME){
                        this.lateFlag = true;
                        }
                        if(this.actualEndTime != "00:00:00"){
                            this.endTimeFlag = true;
                            this.updateEndTimeFlag = true;
                            this.updateStartTimeFlag = false;
                        }
                        if(this.startTimeFlag && this.endTimeFlag){
                            this.circularFlag = false;
                            this.judgeAndReLocFlag = false;
                        }
                    }else if(this.workMode == '签到'){
                        this.startTimeFlag = true
                        this.updateStartTimeFlag = false
                        this.circularFlag = false
                        this.circularQDFlag = false
                        this.judgeAndReLocFlag = false
                        this.takePhoto = true

                    }else if(this.workMode == '签到+拍照'){
                        this.startTimeFlag = true
                        this.updateStartTimeFlag = false
                        this.circularFlag = false
                        this.circularQDFlag = false
                        this.judgeAndReLocFlag = false
                        this.takePhoto = true
                    }
                    

                }

            })
        },
        getCheckPlan(){
            this.$ajax({
                url : this.COMMON_URL,
                method : 'post',
                data : {
                    _method : "PMCOMPRE_CHECKON.getCheckPlanByUserName",
                    USERNAME : this.user.loginId,
                    TODAY : this.today
                },
                async : false
            }).then(res=>{
                console.log("plan",res);
                if(res.data.returnValue.length==0){
                    this.circularFlag = false;
                    this.judgeAndReLocFlag = false;
                     this.toastValue = true;
                   //this.shangxiaban = true;
                    setTimeout(()=>{
                        this.$router.go(-1)
                    },2000)
                    return;
                }
                if(res.data.returnValue.length > 0){
                    this.planList = res.data.returnValue[0];
                    this.workMode = this.planList.WORKMODE;
                    this.planStartTime = this.planList.STARTTIME;
                    this.planEndTime = this.planList.ENDTIME;
                    this.SYSPRJID = this.planList.SYSPRJID;
                    this.PRJNAME = this.planList.PRJNAME;
                    this.workPosition = this.planList.WORKPOSITION;
                    this.planMinDate = this.planList.MINDATE;
                    this.planMaxDate = this.planList.MAXDATE;
                    if(this.workMode == '签到'){
                        this.circularQDFlag = true
                        this.circularFlag = false
                        this.takePhoto = true
                    }else if(this.workMode == '不考勤'){
                        this.toastValueNotOnDuty = true
                        this.circularFlag = false
                        this.judgeAndReLocFlag = false
                    }else if(this.workMode == '上下班'){
                        this.shangxiaban = true
                    }else if(this.workMode == '签到+拍照'){
                        this.takePhoto = true
                        this.circularQDFlag = true
                        this.circularFlag = false
                    }
                    //console.log("workPosition",this.workPosition);
                    //将字符串转换为数组
                    var positions = this.workPosition.split("LatLng");
                    //去除转换后数组的第一个元素即可得到多边形的点
                    positions.splice(0,1);
                   
                    for(var i=0;i<positions.length;i++){
                        if(i != positions.length - 1){
                            positions[i] = positions[i].substring(0,positions[i].length-1);
                        }
                        var temp = positions[i].substring(1,positions[i].length-1);
                        console.log("temp",temp);
                        positions[i] = temp.split(", ");
                        var tempArr = positions[i][0];
                        positions[i][0] = positions[i][1];
                        positions[i][1] = tempArr;
                        positions[i] = positions[i].map(Number);
                         //parseInt(...positions[i])
                        console.log(positions[i].map(Number));
                    }
                    console.log("positions",positions);
                    this.path = positions
                    console.log("path",this.path);
                    this.getCurrentPosition();//获取当前定位信息
                }
            })
        },
        getTime(data){
            var hour = data.getHours();
            var min = data.getMinutes();
            var sec = data.getSeconds();
            if(hour < 10) {
                hour = "0" + hour
            }
            if(min < 10){
                min = "0" + min
            }
            if(sec < 10){
                sec = "0" + sec
            }
            return hour + ":" + min + ":" + sec;
        },
        getUser(){
            console.log("user",this.user);
        },
        getUserImg(){
            this.$ajax({
                url : this.COMMON_URL,
                method : 'post',
                data : {
                    _method : "FIX_ACC_FILE_INFO.getFileWebPath",
                    fieldToken : this.user.UserIconId
                },
                async : false,
            }).then(res=>{
                //console.log("UserImg",res);
                var length = res.data.data.length;
                var imgUrlStr = "";
                if(length > 0){
                    var data = res.data.data[0];
                    imgUrlStr = data.FileUrl;
                    if(imgUrlStr.indexOf("tmpfiledownlaod/qhszpm/") != 1){
                        imgUrlStr = process.env.BASE_URL + '/qhszpm/' + imgUrlStr.substring(imgUrlStr.indexOf("tmpfiledownlaod/qhszpm/"));
                    }
                }
                console.log("imgStr",imgUrlStr);
                this.imgUrl = imgUrlStr;
            })
        }
    }

}
</script>

<style scoped>
.sup{
  width: 100%;
  height: 10px;
  border-radius: 0;
  background-color: #F5F5F5;
  position: absolute;
  top: 530px;
}
.takePhoto{
    position: absolute;
    left: 5px;
    top: 160px;
}
.judgeAndReLoc{
    position: absolute;
    left: calc((100% - 138px)/2);
    top: 500px;
    display: flex;
}
.reLocation{
    font-size:12px;
    font-family:PingFangSC-Regular;
    font-weight:400;
    color:rgba(36,179,131,1);
    line-height:20px;
    margin-left: 10px;
}
.isInScope{
    font-size:12px;
    font-family:PingFangSC-Regular;
    font-weight:400;
    color:rgba(102,102,102,1);
    line-height:20px;
    margin-left: 5px;
}
.updateCard{
    font-size:12px;
    font-family:PingFangSC-Regular;
    font-weight:400;
    color:rgba(36,179,131,1);
    line-height:24px;
    position: absolute;
    top: 220px;
    left: 45px;
}
.updateCard1{
    font-size:12px;
    font-family:PingFangSC-Regular;
    font-weight:400;
    color:rgba(36,179,131,1);
    line-height:24px;
    position: absolute;
    top: 405px;
    left: 45px;
}
.location{
    position: absolute;
    top: 190px;
    left: 45px;
    display: flex;
}
.location1{
    position: absolute;
    top: 375px;
    left: 45px;
    display: flex;
}
.location_text{
    font-size:14px;
    font-family:PingFangSC-Regular;
    font-weight:400;
    color:rgba(153,153,153,1);
    line-height:24px;
}
.late{
    width:62px;
    height:20px;
    border:2px solid rgba(255,173,20,1);
    border-radius:4px;
    color:#FFAD14;
    display: flex;
    justify-content: center;
    align-items: center;
    position: absolute;
    top: 160px;
    left: 175px;
}
.circular_text{
    font-size:18px;
    font-family:PingFangSC-Regular;
    font-weight:400;
    color:rgba(255,255,255,1);
    line-height:20px;
}
.circular_time{
    font-size:14px;
    font-family:PingFangSC-Regular;
    font-weight:400;
    color:rgba(179,181,186,1);
    line-height:20px;
    opacity:0.6;
    margin-top: 5px;
}
.circular{
    width:128px;
    height:128px;
    background:rgba(38,42,52,1);
    border-radius:50%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: absolute;
    left: calc((100% - 128px)/2);
    top: 350px;
}
.circular_text_QD{
    font-size:18px;
    font-family:PingFangSC-Regular;
    font-weight:400;
    color:rgba(255,255,255,1);
    line-height:20px;
}
.circular_time_QD{
    font-size:14px;
    font-family:PingFangSC-Regular;
    font-weight:400;
    color:rgba(255,255,255,1);
    line-height:20px;
    opacity:0.6;
    margin-top: 5px;
}
.circularQD{
    width:128px;
    height:128px;
    background:#FFAD14;
    border-radius:50%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: absolute;
    left: calc((100% - 128px)/2);
    top: 350px;
}
.cardQDTime{
    position: absolute;
    top: 300px;
    left: 45px;
}
.cardTime{
    position: absolute;
    top: 160px;
    left: 45px;
}
.cardTime1{
    position: absolute;
    top: 345px;
    left: 45px;
}
.text_name{
    font-size:16px;
    font-family:PingFangSC-Regular;
    font-weight:400;
    color:rgba(25,25,25,1);
    line-height:20px;
}
.text_dept{
    font-size:13px;
    font-family:PingFangSC-Regular;
    font-weight:400;
    color:rgba(153,153,153,1);
    line-height:20px;
    margin-top: 10px;
}
.info{
    display: flex;
    padding: 10px;
    border-bottom: 1px solid #f5f5f5;
}
.text_info{
    margin-left: 10px;
}
.no_photo{
    width:50px;
    height:50px;
    background:linear-gradient(180deg,rgba(106,135,255,1),rgba(77,102,254,1));
    border-radius:50%;
    font-size:12px;
    font-family:PingFangSC-Regular;
    font-weight:400;
    color:rgba(255,255,255,1);
    line-height:20px;
    display: flex;
    justify-content: center;
    align-items: center;
}
.photo{
    width:50px;
    height:50px;
    border-radius:50%;
}
.transition-view .vux-header /deep/ .vux-header-title {
  line-height: 40px;
  text-align: center;
  font-size: 18px;
  font-weight: 600;
  color: #262A34;
  font-family:PingFangSC-Semibold;
}
.transition-view .weui-wepay-flow /deep/ .weui-wepay-flow__bd{
    align-items: unset;
}
.transition-view .weui-wepay-flow  /deep/ .weui-wepay-flow__bd .weui-wepay-flow__line{
    margin-left: 5px;
}
</style>
